import java.util.*;

public class Test {

    public static void calcWordNums(String[] words){
        Map<String,Integer> map = new HashMap<>();

        for (String word : words) {
//            if(map.get(word) != null)
            if(map.containsKey(word)){
                int oldNums = map.get(word);
                map.put(word,oldNums + 1);
            }else{
                map.put(word,1);
            }
        }

        for (Map.Entry<String,Integer> entry : map.entrySet()) {
            System.out.println("单词" + entry.getKey() + "出现了" + entry.getValue() + "次！");
        }
    }

    public static void main(String[] args) {
        String[] words = {"this","is","a","good","man","this","good","good"};

        calcWordNums(words);
    }

    public static void main4(String[] args) {
        //将 10w 个数据去重
        int[] array = {1,2,3,4,5,6,7,4,3,2,1};
        Set<Integer> set = new HashSet<>();

        for (int i = 0; i < array.length; i++) {
            set.add(array[i]);
        }

        System.out.print(set + " ");
        System.out.println();

        Iterator<Integer> iterator = set.iterator();
        while(iterator.hasNext()){
            System.out.print(iterator.next() + " ");
        }

    }

    public static void main3(String[] args) {
        //找到 10 个数据中第一个重复的数据
        int[] array = {1,2,3,4,5,6,7,3,2,1};
        Set<Integer> set = new HashSet<>();

        for (int i = 0; i < array.length; i++) {
            if(!set.contains(array[i])){
                set.add(array[i]);
            }else{
                System.out.println(array[i]);
                return;
            }
        }
    }

    public static void main2(String[] args) {
        Person person1 = new Person("1234");
        Person person2 = new Person("1234");

        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());
    }



    public static void main1(String[] args) {
        HashBuck hashBuck = new HashBuck();
        hashBuck.put(1,220);
        hashBuck.put(2,110);
        hashBuck.put(3,70);
        hashBuck.put(4,240);
        hashBuck.put(14,9990);
        hashBuck.put(24,770);
        hashBuck.put(7,660);
        hashBuck.put(8,701);

        System.out.println(hashBuck.get(2));
        System.out.println(hashBuck.get(5));
        System.out.println(hashBuck.get(8));
        System.out.println(hashBuck.get(24));
    }
}
